package xiu_xiu.view_A_main;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import xiu_xiu.base.MainActivity;

import com.xiu_xiu.R;

import java.util.ArrayList;

/**
 * Created by 阳 on 2016/4/1.
 */
public class MyActivity extends MainActivity {
    private ListView list;
    private ArrayList<ContentBref> listData = new ArrayList<>();
    private ListViewAdapter adapter;


    public static void startUI(Context context) {
        Intent intent = new Intent(context, MyActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        initview();
        addData();
        setAdapter();
        disposeListener();
        bottomNavigation(R.id.bottom_bar_ll4);


    }

    /**
     * 初始化
     */
    private void initview() {
        setTitleMore(View.INVISIBLE, View.VISIBLE, "个人中心", null, null, null);
        list = (ListView) findViewById(R.id.lv_main_listview);
    }


    /**
     * 添加数据
     */
    private void addData() {
        listData.add(new ContentBref(1, "设置个人资料", R.mipmap.car));
        listData.add(new ContentBref(1, "我的求救", R.mipmap.motorcycle));
        listData.add(new ContentBref(1, "我的救员", R.mipmap.bicycle));
        listData.add(new ContentBref(1, "我的小费", R.mipmap.motorcycle));
        listData.add(new ContentBref(1, "等级说明", R.mipmap.motorcycle));
        listData.add(new ContentBref(1, "关于我们", R.mipmap.motorcycle));
        listData.add(new ContentBref(1, "功能简介", R.mipmap.motorcycle));
    }

    /**
     * 设置adapter
     */
    private void setAdapter() {
        adapter = new ListViewAdapter();
        list.setAdapter(adapter);
    }

    /**
     * 处理监听
     */
    private void disposeListener() {
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            }
        });
    }


    class ListViewAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return listData.size();
        }

        @Override
        public ContentBref getItem(int position) {
            return listData.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.item_my, null);
                holder = new ViewHolder();
                holder.title = (TextView) convertView.findViewById(R.id.text);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.title.setText(listData.get(position).getDescribe());
            return convertView;
        }

        class ViewHolder {
            private TextView title;
        }
    }

    /**
     * 实体类
     */
    class ContentBref {
        private int id;
        private String describe;
        private int image;

        public ContentBref() {
        }

        public ContentBref(int id, String describe, int image) {
            this.id = id;
            this.describe = describe;
            this.image = image;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getDescribe() {
            return describe;
        }

        public void setDescribe(String describe) {
            this.describe = describe;
        }

        public int getImage() {
            return image;
        }

        public void setImage(int image) {
            this.image = image;
        }
    }

}
